package com.game.server.message.proto.execute;

import com.comm.ISession;

import com.game.majiang.config.DataManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.server.db.dao.XyClubChangesQuotaDao;
import com.game.server.db.dao.XyClubContributionLogDao;
import com.game.server.db.entity.UserInfoData;
import com.game.server.db.entity.XyClubInfo;
import com.game.server.db.entity.XyClubMemberInfo;
import com.game.server.message.proto.in.AbstractXYfindPlayerXinYulogReq;
import com.game.server.message.proto.out.XYclubContributionLogStruct;
import com.game.server.message.proto.out.XYclubPlayerxinyuLogStruct;
import com.game.server.message.proto.out.XYfindPlayerXinYulogRsp;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class XYfindPlayerXinYulogReq extends AbstractXYfindPlayerXinYulogReq {

    @Override
    public void Execute(ISession session) {
        LogicClient client = (LogicClient) LogicServer.getInstance().getClient(session.getId());
        if (client != null&&client.checkClick(msgcode)) {
            int limit = 20;
            XYfindPlayerXinYulogRsp rsp = new XYfindPlayerXinYulogRsp();
            XyClubInfo clubInfo = DataManager.getInstance().getMapClub().get(this.clubid);
            if (clubInfo != null) {
                XyClubMemberInfo memberInfo = clubInfo.getPlayer().get(client.getUserId());
                XyClubMemberInfo toMemberInfo = clubInfo.getPlayer().get(this.uid);
                if (memberInfo!=null && toMemberInfo.getDel_type()==0){
                    JSONObject json = XyClubChangesQuotaDao.findPage(limit, this.page, this.clubid, this.uid,this.type);
                    rsp.setAllpage(json.getInt("allpage"));
                    rsp.setAllcount(json.getInt("allcount"));
                    rsp.setPlayerallxinyu(toMemberInfo.getXingyuvalue());
                    rsp.setPage(this.page);
                    JSONArray array = json.getJSONArray("array");
                    XYclubPlayerxinyuLogStruct[] clubPlayerxinyuLogs = new XYclubPlayerxinyuLogStruct[array.size()];
                    int index = 0;
                    for (Object ent : array) {
                        JSONObject object = JSONObject.fromObject(ent);
                        XYclubPlayerxinyuLogStruct clubPlayerxinyuLog = new XYclubPlayerxinyuLogStruct();
                        clubPlayerxinyuLog.setOptime(object.getString("createdate"));
                        clubPlayerxinyuLog.setType(object.getInt("type"));
                        clubPlayerxinyuLog.setQuota(object.getInt("quota"));
                        clubPlayerxinyuLog.setMeId(object.getInt("meUid"));
                        clubPlayerxinyuLog.setResidue(object.getInt("residue"));
                        clubPlayerxinyuLog.setTableonly(object.getLong("roomkey")+"");
                        clubPlayerxinyuLogs[index] = clubPlayerxinyuLog;
                        index++;
                    }

                    UserInfoData infoData = DataManager.getInstance().getMapUserData().get(this.uid);
                    rsp.setName(infoData.getName());
                    rsp.setHeadurl(infoData.getHead());
                    rsp.setUid(infoData.getId());
                    rsp.setClubPlayerxinyuLogs(clubPlayerxinyuLogs);
                }
            }
            client.Send(rsp);
        }
    }

}
